package com.haoshuang.zhouzhoubang.ui.vm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.CallBean
import com.haoshuang.zhouzhoubang.model.bean.EwBean
import com.haoshuang.zhouzhoubang.model.bean.LogBen
import com.haoshuang.zhouzhoubang.model.bean.OrderDetail2Bean
import com.haoshuang.zhouzhoubang.model.bean.PriceBean
import com.haoshuang.zhouzhoubang.model.bean.SmBean
import com.haoshuang.zhouzhoubang.model.bean.TimeBean8
import com.haoshuang.zhouzhoubang.model.bean.YanShou
import com.lnkj.jialubao.ui.page.bean.*
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ServiceOrderStatusViewModel : BaseViewModel() {

    /**
     * 确认上门
     */
    val confirmDoorData = StatefulMutableLiveData<Any>()
    fun confirmDoor(orderId: String) = netRequest {
        start { confirmDoorData.value = StateData.Loading }
        request { ApiRepo.confirmDoor(orderId)  }
        success { confirmDoorData.value = StateData.Success(it.data) }
        error { code, msg ->
            confirmDoorData.value = StateData.Error(code, msg)
        }
    }

    val getData666 = StatefulMutableLiveData<Any>()
    fun getData666(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("api/master_order/sign", *params,
                onStart = {
                    getData666.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData666.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData666.value = StateData.Success(it)
                })
        }
    }

    val getData0 = StatefulMutableLiveData<EwBean>()
    fun getData0(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<EwBean>("/api/auth_api/getOtherCost", *params,
                onStart = {
                    getData0.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData0.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData0.value = StateData.Success(it)
                })
        }
    }

    val getData012 = StatefulMutableLiveData<Any>()
    fun getData012(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/master_order/do_service", *params,
                onStart = {
                    getData012.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData012.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData012.value = StateData.Success(it)
                })
        }
    }

    val getData222 = StatefulMutableLiveData<YanShou>()
    fun getData222(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<YanShou>("/api/master_order/check_order", *params,
                onStart = {
                    getData222.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData222.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData222.value = StateData.Success(it)
                })
        }
    }

    val getData29 = StatefulMutableLiveData<LogBen>()
    fun getData29(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<LogBen>("api/master_order/getServiceLog", *params,
                onStart = {
                    getData29.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData29.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData29.value = StateData.Success(it)
                })
        }
    }

    val getData2 = StatefulMutableLiveData<ArrayList<TimeBean8>>()
    fun getData2(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ArrayList<TimeBean8>>("api/master_order/updateServiceTime", *params,
                onStart = {
                    getData2.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData2.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData2.value = StateData.Success(it)
                })
        }
    }

    val getData55 = StatefulMutableLiveData<ArrayList<PriceBean>>()
    fun getData55(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ArrayList<PriceBean>>("api/master_order/getCostList", *params,
                onStart = {
                    getData55.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData55.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData55.value = StateData.Success(it)
                })
        }
    }

    val getData22 = StatefulMutableLiveData<String>()
    fun getData22(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ArrayList<Any>>("api/master_order/remind_check", *params,
                onStart = {
                    getData22.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData22.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData22.value = StateData.Success(params.first().second.toString())
                })
        }
    }

    val getData3 = StatefulMutableLiveData<Any>()
    fun getData3(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("api/master_order/confirmUpdateServiceTime", *params,
                onStart = {
                    getData3.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData3.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData3.value = StateData.Success(it)
                })
        }
    }

    val getData6 = StatefulMutableLiveData<SmBean>()
    fun getData6(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<SmBean>("api/master_order/is_confirm_door_visit", *params,
                onStart = {
                    getData6.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData6.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData6.value = StateData.Success(it)
                })
        }
    }

    val getData66 = StatefulMutableLiveData<SmBean>()
    fun getData66(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<SmBean>("api/master_order/is_confirm_door_visit", *params,
                onStart = {
                    getData66.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData66.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData66.value = StateData.Success(it)
                })
        }
    }

    val getData = StatefulMutableLiveData<OrderDetail2Bean>()
    fun getData(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<OrderDetail2Bean>("api/master_order/get_master_order_detail", *params,
                onStart = {
                    getData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData.value = StateData.Success(it)
                })
        }
    }
}